package main

import (
	"fmt"
	"time"
)

func main() {

	var (
		ch = make(chan int, 10) // 队列长度 10，队列元素类型为 int
	)

	go func() {
		ticker := time.NewTicker(time.Second)
		counter := 1
		for _ = range ticker.C {
			// 每 1 秒往队列中放入一个类型为 int 的元素，队列满时生产者可以阻塞
			ch <- counter
			counter++
		}
	}()

	for counter := range ch {
		// 每一秒从队列中获取一个元素并打印，队列为空时消费者阻塞
		fmt.Println("receive", counter)
		time.Sleep(time.Second)
	}

}
